# -*- coding: utf-8 -*-
from devicetest.core.test_case import TestCase, Step, CheckPoint
from hypium import *
from hypium.uidriver import Gesture, gesture

from aw.Common import Functions

pkgName = 'com.example.pycase'


class DragPredragsTestLeveL3001(TestCase):

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        self.tests = ['test_step']
        TestCase.__init__(self, self.TAG, controllers)
        Functions.test_case_init(self, 'com.example.pycase')
        self.explore = Functions.explore(self.device1)
        self.driver_width, self.driver_height = self.explore.get_display_size()

    def setup(self):
        self.explore.swipe_to_home()

    def test_step(self):
        Step("SUB_ACE_ACTION_EVENT_COMMONEVENT_DRAG_PREDRAGSTATUS_0090")
        self.explore.start_app(pkgName, page_name="EntryAbility")
        self.explore.touch(BY.text('ActionEventCommonEventDragPreDragStatus'))
        self.explore.wait(1)
        self.explore.touch(BY.key('ActionEventCommonEventDragPreDragStatus0090'))
        self.explore.wait(1)

        CheckPoint("检测点 初始状态前")
        case_name = Functions.generate_case_name(self)
        Functions.take_picture(self, self.explore, case_name)
        Functions.compare_pics_by_hash(self, case_name, similar=0.99)

        pos = self.explore.find_component(BY.key("img"))
        gesture1 = gesture.Gesture().start(pos.getBoundsCenter().to_tuple(), interval=10)
        self.explore.inject_gesture(gesture1)

        CheckPoint("检测点 长按后的页面1")
        case_name = Functions.generate_case_name(self)
        Functions.take_picture(self, self.explore, case_name)
        Functions.compare_pics_by_hash(self, case_name, similar=0.99)

        self.explore.wait(1)
        CheckPoint("检测点 长按后的页面2")
        case_name = Functions.generate_case_name(self)
        Functions.take_picture(self, self.explore, case_name)
        Functions.compare_pics_by_hash(self, case_name, similar=0.99)

    def teardown(self):
        self.explore.stop_app(pkgName)
        Functions.write_config(self)
